
#if	!defined( __20090326_DEF_TIME_H__ )
#define	__20090326_DEF_TIME_H__

#if	defined( PCE_CFG_OS_Windows )

#include	<sys/types.h>
#include	<sys/timeb.h>
#include	<time.h>

namespace PCE_Lib {
namespace CEnv_Def {
namespace PCE_Lib_CurrentCEnvironment {
namespace Tools {

class Time
{
public:
	static bool Second( uint64_t & time ) throw()
	{
		time = uint64_t( _time64( Null< __time64_t * >() ) );
		return true;
	}
	static bool MilliSecond( uint64_t & time ) throw()
	{
		struct __timeb64	tv;

		if( 0 != _ftime64_s( & tv ) ) {
			return false;
		}

		time = tv.time * 1000 + tv.millitm;
		return true;
	}
private:
	Time( void ) throw() {}
};

}	// Tools
}	// PCE_Lib_CurrentCEnvironment
}	// CEnv_Def
}	// PCE_Lib

#elif	defined( PCE_CFG_OS_Linux )

#include	<sys/time.h>

namespace PCE_Lib {
namespace CEnv_Def {
namespace PCE_Lib_CurrentCEnvironment {
namespace Tools {

class Time
{
public:
	static bool Second( uint64_t & time ) throw()
	{
		struct timeval	tv;

		if( 0 != gettimeofday( &tv, Null< struct timezone * >() ) ) {
			return false;
		}
		time = tv.tv_sec;
		return true;
	}
	static bool MilliSecond( uint64_t & time ) throw()
	{
		struct timeval	tv;

		if( 0 != gettimeofday( &tv, Null< struct timezone * >() ) ) {
			return false;
		}
		time = tv.tv_sec * 1000 + tv.tv_usec / 1000;
		return true;
	}
private:
	Time( void ) throw() {}
};

}	// Tools
}	// PCE_Lib_CurrentCEnvironment
}	// CEnv_Def
}	// PCE_Lib

#else
	#error Time.h can only be used on Windows platform and Linux platform!
#endif	// PCE_CFG_OS_Windows && PCE_CFG_OS_Linux

#endif	// __20090326_DEF_TIME_H__
